"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

/**
 * 
 * @desc  设置localstorage
 * @param {String} key 
 * @param {Any} value
 */
function setItem(key, value) {
  if (!key || value !== 0 && !value) return;
  key = key.toString();

  if (_typeof(value) === "object") {
    value = JSON.stringify(value);
  }

  localStorage.setItem(key, value);
}
/**
 * 
 * @desc  获取localstorage
 * @param {String} key 
 * @param {Any} value
 */


function getItem(key, value) {
  if (!key) return;
  key = key.toString();
  var data = localStorage.getItem(key);
  return data ? data : value;
}
/**
 * 
 * @desc  删除localstorage
 * @param {String} key
 */


function removeItem(key) {
  if (!key) return;
  key = key.toString();
  localStorage.removeItem(key);
}

var safeStorage = {
  setItem: setItem,
  getItem: getItem,
  removeItem: removeItem
};
module.exports = safeStorage;